clear all
set type double
set varabbrev on, perm

*** FILL IN MAIN PATH TO RUN CODE ***
global dropbox "..."

global folder "$dropbox/_0_bjps_replication"
global in "$folder/in"
global out "$folder/out"
global proc "$folder/proc"

global graph "$out/graph"
global table "$out/table"
global temp "`c(tmpdir)'"


// Import data
import excel "$proc/final_job_info_codings.xlsx", sheet("Simplified") firstrow clear

// Exclude entries not listing a political party
drop if missing(political_party)

// Create dummy variable for Republicans to be able to count all Republicans
gen is_republican = (political_party == "Republican" | independent_type == "Republican Party")

// Calculate counts for each category and for Republicans within each category
bysort category: gen category_count = _N
bysort category: egen republican_sum = total(is_republican)

// Calculate percentage of Republican owners
gen republican_pct = (republican_sum / category_count) * 100

// Place each category into one of five groups based on % Republican
gen group = ""
replace group = "Very Democratic" if republican_pct <= 20
replace group = "Somewhat Democratic" if republican_pct > 20 & republican_pct <= 40
replace group = "Neutral" if republican_pct > 40 & republican_pct <= 60
replace group = "Somewhat Republican" if republican_pct > 60 & republican_pct <= 80
replace group = "Very Republican" if republican_pct > 80

sa "$temp/ind_code", replace

u "$proc/survey_reg_base.dta", clear

keep if sample == "verasight"
merge 1:1 case_id using "$temp/ind_code", assert(1 3)nogen keepusing(group)
drop if mi(group)

collapse (rawsum)weight, by(group employer_SBO)
reshape wide weight, i(group)j(employer_SBO)
g tot = weight0+weight1
g pct0 = weight0/tot
g pct1 = weight1/tot
